/**
 * 
 */
package com.android.cherryboard.Deshboard;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.android.cherryboard.R;
import com.android.cherryboard.AddCherryboard.AddCherryboardActivity;
import com.android.cherryboard.Task.GetCherryboardListTask;
import com.android.cherryboard.Utility.ImageLoader;
import com.android.cherryboard.Utility.Utility;

/**
 * @author ashu
 * 
 */
public class CherryfullDashboardActivity extends Activity implements android.view.View.OnClickListener {

	private static final int REQUEST_CODE_ADD_CHERRYBOARD = 0;
	private GridView gridViewMyCherryboard;

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		switch (resultCode ) {
		case Activity.RESULT_OK:
			if (requestCode == REQUEST_CODE_ADD_CHERRYBOARD) {

				GetCherryboardListTask cherryboardListTask = new GetCherryboardListTask(
						gridViewMyCherryboard);
				String params = "http://cherryfull.com/app_services_data.php?tbl=tbl_app_cherryboard&tblFields=cherryboard_id,cherryboard_title&fb_id="+Utility.userUID;
				cherryboardListTask.execute(params);
				
					
			}
			
			
			break;

			
			
			
		default:
			break;
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cherryfull_deshboard_view);

		setView();
	}

	private void setView() {
		// TODO Auto-generated method stub

		TextView tvUserName = (TextView) this
				.findViewById(R.id.textView_app_header_user_name);
		ImageView ivUserPic = (ImageView) this
				.findViewById(R.id.imageView_app_header_user_image);

		tvUserName.setText(Utility.userName);
		ivUserPic.setImageBitmap(Utility.getBitmap(Utility.userPicURL));
		
		ImageLoader imageLoader = new ImageLoader(this);
		imageLoader.DisplayImage(Utility.userPicURL, ivUserPic);
 
		/*ListView listViewCherryboard = (ListView) this
				.findViewById(R.id.listView_my_cherryboard);*/
		
		gridViewMyCherryboard = (GridView)this.findViewById(R.id.gridView_my_cherryboard);
		GetCherryboardListTask cherryboardListTask = new GetCherryboardListTask(
				gridViewMyCherryboard);
		String params = "http://cherryfull.com/app_services_data.php?tbl=tbl_app_cherryboard&tblFields=cherryboard_id,cherryboard_title&fb_id="+Utility.userUID;
		cherryboardListTask.execute(params);
		
		
		Button addCherryBoard = (Button)this.findViewById(R.id.button_add_cherryboard);
		addCherryBoard.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		switch (v.getId()) {
		case R.id.button_add_cherryboard:
			
			Intent intentAddCherryboard = new Intent(v.getContext(), AddCherryboardActivity.class);
			startActivityForResult(intentAddCherryboard, REQUEST_CODE_ADD_CHERRYBOARD); 
			break;

		default:
			break;
		}
	}

}
